package yanyan.com.tochar.fragment;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;


import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import yanyan.com.tochar.R;
import yanyan.com.tochar.adpter.CommonListAdapter;
import yanyan.com.tochar.beans.HomeListBean;
import yanyan.com.tochar.utils.CoreUtil;
import yanyan.com.tochar.utils.ToastUtil;

public class Other extends Fragment {


    private View view;
    private Context context;
    private ListView listView;
    private List<HomeListBean> listBeans;

//    private Tencent tencent;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.main_other,container,false);
        listView=view.findViewById(R.id.main_other_list);
        initListView();
//       tencent= Tencent.createInstance("101417006",context);
        return view;

    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context=getActivity();
    }

    private void initListView(){
        listBeans=new ArrayList<>();
        HomeListBean b1=new HomeListBean(R.mipmap.ic,"版本更新",CoreUtil.getVsrsionInfo(context),null,null);
        HomeListBean b2=new HomeListBean(R.mipmap.ic,"软件官网","软件官网-待开发",null,null);
        HomeListBean b3=new HomeListBean(R.mipmap.ic,"开发者-点击提问","邮箱:yanjk@vip.qq.com",null,null);
        HomeListBean b4=new HomeListBean(R.mipmap.ic,"加入官方群","遇到问题可加群向群友提问",null,null);
        HomeListBean b5=new HomeListBean(R.mipmap.ic,"软件源码","点击获取软件源码",null,null);
        listBeans.add(b1);
        listBeans.add(b2);
        listBeans.add(b3);
        listBeans.add(b4);
        listBeans.add(b5);
        CommonListAdapter commonListAdapter=new CommonListAdapter(context,listBeans);
        listView.setAdapter(commonListAdapter);


        //监听事件
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                HomeListBean bean=listBeans.get(position);
                if(bean.getActivity()!=null){
                    Intent in=new Intent();
                    in.setClass(context,bean.getActivity().getClass());
                    startActivity(in);
                }
                if(bean.getTitle().equals("版本更新")){
                    CoreUtil.detectionUpdate2(context);
                }

                if(bean.getTitle().equals("加入官方群")){
                    CoreUtil.joinQQGroup(context,"AOzZSjzgi_pYpAbHJbFubhDLju3qcRfn");
                }
                if(position==2){

                }

                switch (position){
                    case 0:
                        CoreUtil.detectionUpdate2(context);
                        break;
                    case 1:
                        ToastUtil.showLongToast(context,"待开发");
                        break;
                    case 2:
                        Uri uri= Uri.parse("mqqwpa://im/chat?chat_type=wpa&uin=201222510&version=1&src_type=web&web_src=oicqzone.com");
                        Intent intent=new Intent(Intent.ACTION_VIEW,uri);
                        startActivity(intent);
                        break;
                    case 3:
                        CoreUtil.joinQQGroup(context,"AOzZSjzgi_pYpAbHJbFubhDLju3qcRfn");
                        break;
                    case 4:
                        ToastUtil.showLongToast(context,"正在整理一些数据，整理完毕开源");
                        break;
                }

            }
        });
    }
}
